package com.yundong.gongchengji.ui.my.activity;

import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.EditText;
import android.widget.PopupWindow;
import android.widget.TextView;

import com.yundong.gongchengji.R;
import com.yundong.gongchengji.base.BaseActivity;
import com.yundong.gongchengji.views.NumberPickerView;
/**
 * 添加银行卡
 * Created by ls on 2017/2/21.
 */

public class AddBankcardActivity extends BaseActivity implements View.OnClickListener {
    private View titleUsername;
    private View titleBankaccount;
    private TextView textBank;

    private EditText editUserName;
    private EditText editAccount;
    private NumberPickerView numberpicker;//选择器
    private String[] city = {"中国工商银行","中国民生银行","中国银行"};
    private PopupWindow popupWindow;
    @Override
    public int getContentViewId() {
        return R.layout.activity_add_bankcard;
    }

    @Override
    protected void initView(Bundle savedInstanceState) {
        setLeft();
        setTitle("添加银行");

        textBank= (TextView) findViewById(R.id.text_bank);
        titleUsername=findViewById(R.id.title_username);
        titleBankaccount=findViewById(R.id.title_bankaccount);
        editUserName= (EditText) titleUsername.findViewById(R.id.edit_daan);
        editAccount= (EditText) titleBankaccount.findViewById(R.id.edit_daan);
    }

    @Override
    protected void initVariable() {
        textBank.setOnClickListener(this);

        ((TextView)titleUsername.findViewById(R.id.text_context)).setText("户名");
        ((TextView)titleBankaccount.findViewById(R.id.text_context)).setText("账号");

        editUserName.setHintTextColor(getResources().getColor(R.color.colorQianGray));
        editUserName.setHint("户名");
        editAccount.setHintTextColor(getResources().getColor(R.color.colorQianGray));
        editAccount.setHint("账号");
    }

    @Override
    protected void processLogic(Bundle savedInstanceState) {

    }

    public void showPopu(){
        View view = LayoutInflater.from(this).inflate(R.layout.popu_layout_bottom, null);
        popupWindow = new PopupWindow(view, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT, true);

        //设置显示消失动画
        popupWindow.setBackgroundDrawable(new ColorDrawable(0x00000000));
        WindowManager.LayoutParams lp = getWindow().getAttributes();
        lp.alpha = 0.4f;
        getWindow().setAttributes(lp);
        popupWindow.showAtLocation(view, Gravity.BOTTOM, 0, 0);
        popupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
            @Override
            public void onDismiss() {
                WindowManager.LayoutParams lp =getWindow().getAttributes();
                lp.alpha = 1.0f;
                getWindow().setAttributes(lp);
            }
        });
        TextView textType= (TextView) view.findViewById(R.id.text_type);
        textType.setText("选择银行");
        numberpicker= (NumberPickerView) view.findViewById(R.id.numberpicker);

        numberpicker.setDisplayedValues(city);
        numberpicker.setMinValue(0);
        numberpicker.setMaxValue(city.length - 1);
        numberpicker.setValue(0);//设置第一次显示的位置


        TextView textCanel= (TextView) view.findViewById(R.id.text_canel);
        TextView textOk= (TextView) view.findViewById(R.id.text_ok);
        textCanel.setOnClickListener(this);
        textOk.setOnClickListener(this);
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.text_bank:
                showPopu();
                break;
            case R.id.text_ok:
                showToast(this,city[numberpicker.getValue()]);
                popupWindow.dismiss();
                break;
            case R.id.text_canel:
                popupWindow.dismiss();
                break;
        }
    }
}
